
package com.ami.kvm.jviewer.soc.video;

import com.ami.kvm.jviewer.gui.JViewerApp;
import com.ami.kvm.jviewer.gui.JViewerView;
import com.ami.kvm.jviewer.jvvideo.JVVideo;
import com.ami.kvm.jviewer.soc.SOCCreateBufferImage;
import com.ami.kvm.jviewer.soc.SOCJVVideo;
import java.awt.Rectangle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;

public class HardwareCursor {
	private short[] m_pattern = new short[4096];
	private byte[] CursorColorData = new byte[3];

	private int CursorData;
	private int Alpha;
	private byte ANDBit;
	private byte XORBit;
	private int cursorType;
	private int checksum;
	private short xpos;
	private short ypos;
	private short xoffset;
	private short yoffset;
	private boolean m_firstTime = true;

	private Rectangle m_prevCursorRect;
	private Rectangle m_currCursorRect;
	private JViewerView viewerView;
	private SOCJVVideo socVideo;

	public HardwareCursor(JVVideo paramJVVideo) {
		this.viewerView = JViewerApp.getInstance().getRCView();
		this.socVideo = ((SOCJVVideo) paramJVVideo.getVideoSOC());

		this.m_prevCursorRect = new Rectangle(0, 0, 0, 0);
		this.m_currCursorRect = new Rectangle(0, 0, 64, 64);
	}

	public void set(ByteBuffer paramByteBuffer) {
		paramByteBuffer.rewind();
		paramByteBuffer.order(ByteOrder.LITTLE_ENDIAN);

		this.cursorType = paramByteBuffer.get();
		this.checksum = paramByteBuffer.getInt();
		this.xpos = paramByteBuffer.getShort();
		this.ypos = paramByteBuffer.getShort();
		this.xoffset = paramByteBuffer.getShort();
		this.yoffset = paramByteBuffer.getShort();
		if (paramByteBuffer.remaining() > 0) {
			ShortBuffer localShortBuffer = paramByteBuffer.asShortBuffer();
			localShortBuffer.get(this.m_pattern);
		}
	}

	public void drawCursor() {
		int i = 0;
		int j = this.viewerView.viewWidth();
		int k = this.viewerView.viewHeight();

		if (!this.m_firstTime) {
			this.socVideo.RestoreScreenContent(this.m_prevCursorRect);
			this.viewerView.repaint(this.m_prevCursorRect);
		} else {
			this.m_firstTime = false;
		}

		this.m_currCursorRect.setLocation(this.xpos, this.ypos);
		int m = j - this.xpos < 64 ? j - this.xpos : 64;
		int n = k - this.ypos < 64 ? k - this.ypos : 64;
		this.m_currCursorRect.setSize(m, n);

		this.socVideo.SaveScreenContent(this.m_currCursorRect);
		this.m_prevCursorRect.setBounds(this.m_currCursorRect);
		byte[] arrayOfByte = ((SOCCreateBufferImage) JViewerApp.getInstance().getPrepare_buf()).imageMemoryByte();

		for (int i1 = 0; i1 < 64 - this.yoffset; i1++) {
			if (i1 + this.ypos < k) {

				for (int i2 = 0; i2 < 64 - this.xoffset; i2++)
					if (i2 + this.xpos < j) {

						i = ((i1 + this.ypos) * j + (i2 + this.xpos)) * 3;

						this.CursorData = this.m_pattern[((i1 + this.yoffset) * 64 + (i2 + this.xoffset))];

						this.CursorColorData[0] = ((byte) ((this.CursorData & 0xF00) >> 4));
						this.CursorColorData[1] = ((byte) (this.CursorData & 0xF0));
						this.CursorColorData[2] = ((byte) ((this.CursorData & 0xF) << 4));

						if (this.cursorType == 1) {
							this.Alpha = ((this.CursorData & 0xF000) >> 12);

							arrayOfByte[(i + 2)] = ((byte) ((15 - this.Alpha) * arrayOfByte[(i + 2)] / 15
									+ this.Alpha * this.CursorColorData[0] / 15));
							arrayOfByte[(i + 1)] = ((byte) ((15 - this.Alpha) * arrayOfByte[(i + 1)] / 15
									+ this.Alpha * this.CursorColorData[1] / 15));
							arrayOfByte[i] = ((byte) ((15 - this.Alpha) * arrayOfByte[i] / 15
									+ this.Alpha * this.CursorColorData[2] / 15));
						} else {
							this.ANDBit = ((byte) ((this.CursorData & 0x8000) >> 15));
							this.XORBit = ((byte) ((this.CursorData & 0x4000) >> 14));

							if (this.ANDBit == 0) {
								arrayOfByte[(i + 2)] = this.CursorColorData[0];
								arrayOfByte[(i + 1)] = this.CursorColorData[1];
								arrayOfByte[(i + 0)] = this.CursorColorData[2];
							} else if (this.XORBit != 0) {
								arrayOfByte[(i + 2)] = ((byte) (arrayOfByte[(i + 2)] ^ 0xFFFFFFFF));
								arrayOfByte[(i + 1)] = ((byte) (arrayOfByte[(i + 1)] ^ 0xFFFFFFFF));
								arrayOfByte[i] = ((byte) (arrayOfByte[i] ^ 0xFFFFFFFF));
							}
						}
					}
			}
		}
		this.viewerView.repaint(this.m_currCursorRect);
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer-SOC.jar!\com\ami\kvm\jviewer\soc\video\
 * HardwareCursor.class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */